﻿using DeviceDebugger.DataAccess;
using DeviceDebugger.Model;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace DeviceDebugger.ViewModel
{
    public class ProtocolViewModel : ViewModelBase
    {
        private ObservableCollection<ProtocolModel> _listProtocol;
        public ObservableCollection<ProtocolModel> ListProtocol
        {
            get { return _listProtocol; }
            set { _listProtocol = value; RaisePropertyChanged(() => ListProtocol); }
        }

        private ProtocolModel _selectItem;
        public ProtocolModel SelectItem
        {
            get { return _selectItem; }
            set { _selectItem = value; RaisePropertyChanged(() => SelectItem); }
        }

        /// <summary>
        /// 单元格修改事件
        /// </summary>
        public RelayCommand CellEditCommand => new RelayCommand(CellEditCommand_Event);
        public RelayCommand<Window> CloseWindowCommand => new RelayCommand<Window>(CloseWindowCommand_Click);
        public RelayCommand ChbShowCommand => new RelayCommand(CellEditCommand_Event);


        private void CloseWindowCommand_Click(Window window)
        {
            window.Close();
        }

        public ProtocolViewModel()
        {
            ListProtocol = new(DataVisitor.GetProtocols());
        }

        private void CellEditCommand_Event()
        {
            if (SelectItem != null)
            {
                DataVisitor.EditProtocol(SelectItem);
            }
        }
    }
}
